package com.weixing.mall.provider.controller.rpc;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.api.model.vo.AgentRebateRuleInfoVo;
import com.weixing.mall.provider.model.domain.AgentBonusRule;
import com.weixing.mall.provider.model.domain.AgentDiscount;
import com.weixing.mall.provider.api.model.vo.AgentDiscountVo;
import com.weixing.mall.provider.model.domain.AgentRebateRuleInfo;
import com.weixing.mall.provider.api.model.vo.AgentBonusRuleVo;
import com.weixing.mall.provider.service.IAgentBonusRuleService;
import com.weixing.mall.provider.service.IAgentDiscountService;
import com.weixing.mall.provider.service.IAgentRebateRuleInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName AgentDiscountController
 * @Description
 * @Author Small
 * @Date 2019/10/17 11:09
 * @Version 1.0
 **/
@RestController
@RequestMapping("api/agent/act")
public class AgentDiscountRpcController extends BaseController {

    @Autowired
    private IAgentDiscountService agentDiscountService;
    @Autowired
    private IAgentRebateRuleInfoService agentRebateRuleInfoService;
    @Autowired
    private IAgentBonusRuleService agentBonusRuleService;

    @GetMapping("discount")
    public Result detail(Long id){
        AgentDiscount agentDiscount = agentDiscountService.getById(id);
        if (null == agentDiscount){
            return ResultUtil.error("折扣规则不存在");
        }
        AgentDiscountVo vo = new AgentDiscountVo();
        BeanUtils.copyProperties(agentDiscount,vo);
        return ResultUtil.success(vo);
    }

    @GetMapping("rebaterule")
    public Result rebateRuleInfoDetail(Long ruleId,Integer ruleCode){
        AgentRebateRuleInfo byRuleIdAndRuleCode = agentRebateRuleInfoService.findByRuleIdAndRuleCode(ruleId, ruleCode);
        if (null == byRuleIdAndRuleCode){
            return ResultUtil.error("返利规则不存在");
        }
        AgentRebateRuleInfoVo vo = new AgentRebateRuleInfoVo();
        BeanUtils.copyProperties(byRuleIdAndRuleCode,vo);
        return ResultUtil.success(vo);
    }

    @GetMapping("bonusrule")
    public Result bonusruleDetail(Integer orderType){
        AgentBonusRule byRuleIdAndRuleCode =  agentBonusRuleService.findByOrderType(orderType);
        if (null == byRuleIdAndRuleCode){
            return ResultUtil.error("分红规则不存在");
        }
        AgentBonusRuleVo vo = new AgentBonusRuleVo();
        BeanUtils.copyProperties(byRuleIdAndRuleCode,vo);
        return ResultUtil.success(vo);
    }
}
